package com.lyd.basic;

import java.util.Objects;

/**
 * @Author:lyd
 **/
public class CopyTest {
    public static void main(String[] args) {
        //浅拷贝
        Person person = new Person("张三", 20);
        Person personCopy = person.clone();
        System.out.println(person == personCopy);
        System.out.println(Objects.equals(personCopy.getName(), person.getName()));
        System.out.println(person);
        System.out.println(personCopy);

        //浅拷贝的局限性；如果原对象的成员变量是引用类型的话则是引用拷贝，
        // 原对象和拷贝后的对象共用同一个内部对象
        Address address = new Address("苏州");
        Person person2 = new Person("李四", 34, address);
        Person person2Copy = person2.clone();
        address.setAddressName("成都");
        System.out.println(person2);
        System.out.println(person2Copy);

    }
}
